package cn.mrlong.keeplive;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import cn.mrlong.keeplive.keeplive.InitSaveUtil;
import cn.mrlong.keeplive.keeplive.ScreenReceiverUtil;

public class MainActivity extends AppCompatActivity {

    private ScreenReceiverUtil screenReceiverUtil;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button one = findViewById(R.id.one);
        one.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this, OneActivity.class));
            }
        });
        Button two = findViewById(R.id.two);
        two.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this, TwoActivity.class));
            }
        });

        //A 本案例保活步骤：
        //1、配置权限
        //2、配置Manifest中的Service
        //3、修改Contants中的包名
        //4、修改引用MainActivity （SinglePixelActivity、AliveJobService）
        //5、动态注册广播
        //6、在activity中启动
        //7、添加mp3资源、配置style样式

        //动态广播 只需要注册一次（建议写在一个 不易销毁的activity中）
        screenReceiverUtil = new ScreenReceiverUtil(this);
        screenReceiverUtil.register();
        //每个Activity 都写这句话
        new InitSaveUtil(this).startSaveMethod();

        //B 、其他保活：开启电量优化、手动开启程序后台运行、电池白名单；
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (null != screenReceiverUtil) {
            screenReceiverUtil.unRegister();
        }
    }
}
